<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <div>
      <span>全选:</span>
      <input type="checkbox" @click="allcheck" :checked="arr.every(v=>v.checked)">
      <button @click="reverse">反选</button>
      <ul>
        <li v-for="(item,index) in arr" :key="index">
          <input type="checkbox" v-model="item.checked"/>
          <span>{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
  <script src="./lib/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        arr: [
          {
            id:1,
            name: "猪八戒",
            checked: false,
          },
          {
            id:2,
            name: "孙悟空",
            checked: false,
          },
          {
            id:3,
            name: "唐僧",
            checked: false,
          },
          {
            id:4,
            name: "白龙马",
            checked: false,
          },
        ],
      },
      methods:{
        // 全选
        allcheck(e){
          this.arr.forEach((item) => {
            console.log(e.target.checked);
            item.checked = e.target.checked
          })
        },
        // 反选
        reverse(){
          this.arr.forEach((item) => {
            item.checked = !item.checked
          })
        }
      }
    })
  </script>


</body>

</html>